<?php
session_start();
require_once('models/Validator.class.php');

function getExtension($str)
{
     $i = strrpos($str,".");
     if (!$i) { return ""; }
     $l = strlen($str) - $i;
     $ext = substr($str,$i+1,$l);
     return $ext;
}

foreach ($_FILES['photos']['name'] as $name => $value)
{
     $filename = stripslashes($_FILES['photos']['name'][$name]);    
     $size=$_FILES['photos']['size'][$name];
     $ext = getExtension($filename);
     $mime_type=$_FILES['photos']['type'][$name];
     
     if(!Validator::validateUploadedImage($filename, $mime_type, $size)) 
    {	 
         trigger_error("Not validate uploaded Image filename=$filename, Extension=$ext, Size=$size. Details: ". Validator::$error_msg, E_USER_WARNING);         
         exit;
    }
    
}

require_once('models/Image.class.php');
require_once('configs/db_connect.php');
$image = new Image();
$result=$image->moveAll($_FILES,  $_SESSION['photoalbum_id'],  $_SESSION['user_id']);

if (!$result)
{
      trigger_error("Photos hasn't been moved ". Image::$error_msg, E_USER_WARNING);
}
else 
{
     echo json_encode($result);
}
